function [U1,U2,bondprice,bidask_bond,priceimpactbond,bidask_cds,riskfreerate,cdsvolume,CDS_basis] = output_complete(controls,pi1,w1,w2,y1vec,y2vec,yf,gamma,gammaf,relativesize,bondpayoff)
%This function computes equilibrium outcomes for the complete-markets economy

a1=controls(1:2);%asset positions of Type 1
a2=-a1;%Back out from market clearing with a small fringe
af=controls(3:4);

pivec=[pi1,1-pi1];

cf=yf+af;

pricesAD=pivec.*(cf).^(-gammaf); %Prices
riskfreerate= 100 * (1/sum(pricesAD)-1);
 
b = bondpayoff(2);
bondprice = (1 - pi1) * b .* (cf(2)).^(-gammaf);

c01=w1-sum(pricesAD.*a1); %Type 1 consumption within the period
c02=w2-sum(pricesAD.*a2); %Type 2 consumption within the period

c1prime=y1vec + a1; %Type 1: 1x2 vector of state-contingent updated wealth
c2prime=y2vec + a2; %Type 2: 1x2 vector of state-contingent updated wealth


if gamma==1
    
    U1=log(c01) + pi1*log(c1prime(1)) + (1-pi1)*log(c1prime(2));
    U2=log(c02) + pi1*log(c2prime(1)) + (1-pi1)*log(c2prime(2));

else
    
    U1=((c01)^(1-gamma))/(1-gamma) + pi1*((c1prime(1))^(1-gamma))/(1-gamma) + (1-pi1)*((c1prime(2))^(1-gamma))/(1-gamma);
    U2=((c02)^(1-gamma))/(1-gamma) + pi1*((c2prime(1))^(1-gamma))/(1-gamma) + (1-pi1)*((c2prime(2))^(1-gamma))/(1-gamma);

end

priceimpactbond=relativesize*sum(gammaf*(1-pi1).*(b^2).*(cf).^(-gammaf-1));


% Compute state prices
Lambda1=(pivec.* c1prime.^-gamma)./(c01^(-gamma));
Lambda2=(pivec.* c2prime.^-gamma)./(c02^(-gamma));

cdsprice=pi1*b*(cf(1))^(-gammaf);
cdsvolume=2*abs(a1(1));

bidask_bond = (Lambda1(2) - Lambda2(2)) / cdsvolume; %fraction of par
bidask_cds = cdsvolume \ b * (Lambda1(1)-Lambda2(1)) / cdsprice; %fraction of mid

CDS_basis = (pi1 * b / cdsprice - (1 - pi1) * b / bondprice) / cdsvolume;

end